if (!(typeof (_EXCELBOOK_QUERY) == "object")) {
    (function () {
        //private static property
        var m_numberInstances = 0
            , m_appExcel = null

        _EXCELBOOK_QUERY = function () {
            ++m_numberInstances

            //public property
            this.m_jsonQuery = {}

            //public methods
            this.connect = function (fullPath) {
                var bRes = true

                try {
                    if (m_appExcel == undefined) {
                        err = undefined

                        try { /*m_appExcel = Server.CreateObject("Excel.Application")*/m_appExcel = new ActiveXObject("Excel.Application") }
                        catch (err) {
                            bRes = false
                        }
                    }
                    else
                        ;
                     
                }
                catch (err) {
                    bRes = false
                }

                if (typeof (err) == "undefined") {
                    try {
                        var iRes = m_appExcel.Workbooks.Open(fullPath, 0, true) //, 0, true, 0, "password", "password"       
                    }
                    catch (err) {
                    }

                    if (typeof (err) == "undefined") {
                    }
                    else
                        bRes = false
                }
                else
                    bRes = false

                return bRes
            }

            this.disconnect = function () {
                m_appExcel.ActiveWorkbook.Saved = true
                m_appExcel.ActiveWorkbook.Close()
                m_appExcel.Quit()

                m_appExcel = null
            }

            this.query = function (what) {
                this.m_jsonQuery = {}

                try {
                    var rows = what.fields.rows.split(","), r = -1,
                        cols = what.fields.cols.split(","), c = -1

                    while (rows.length) {
                        r = parseInt(rows.pop())
                        this.m_jsonQuery[r] = {}
                        c = 0
                        while (c < cols.length) {
                            this.m_jsonQuery[r][parseInt(cols[c])] = m_appExcel.Activeworkbook.Sheets(what.from).Cells(r, parseInt(cols[c])).Value
                            c++
                        }
                    }
                }
                catch (err) {
                }

                if (typeof (err) == "undefined") {
                }
                else
                    ;
            }
        }

        //public static method
        _EXCELBOOK_QUERY.getNumberInstances = function () {
            return numberInstances
        }
    })()
}
else
    ;